#property indicator_separate_window
#property indicator_buffers 8

int data_hole = 10;
int refresh_period_sec = 10;

extern bool optimize = true;
extern double koef_1440 = 1.0;
extern double koef_240 = 1.0;//0.5;
extern double koef_60 = 1.0;//0.25;
extern double koef_30 = 1.0;//0.15;
extern double koef_15 = 1.0;//0.1;
extern double koef_5 = 1.0;//0.05;
extern double koef_1 = 1.0;//0.025;
extern int TrendCCI_Period=55; // 14
extern int EntryCCI_Period=13; // 6
extern int LSMAPeriod=25;      // LSMA period
extern int Trend_period=2;     // 5
extern string indiName = "CCI_Woodies_Lnx";

//---- buffers
double BufferEUR[];
double BufferGBP[];
double BufferUSD[];
double BufferCAD[];
double BufferAUD[];
double BufferNZD[];
double BufferCHF[];
double BufferJPY[];

double EURUSD;
double EURGBP;
double EURCAD;
double EURCHF;
double EURJPY;
double EURAUD;
double EURNZD;
double GBPUSD;
double GBPCAD;
double GBPCHF;
double GBPJPY;
double GBPAUD;
double GBPNZD;
double USDCAD;
double USDCHF;
double USDJPY;
double AUDUSD;
double NZDUSD;
double CADCHF;
double CADJPY;
double AUDCAD;
double NZDCAD;
double AUDCHF;
double AUDJPY;
double AUDNZD;
double NZDCHF;
double NZDJPY;
double CHFJPY;

bool started = false;
datetime timestart = 0;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   started = false;
   
   SetIndexStyle(0,DRAW_LINE );
   SetIndexBuffer(0,BufferEUR);
   SetIndexLabel(0,"EUR");

   SetIndexStyle( 1, DRAW_LINE );
   SetIndexBuffer(1,BufferGBP);
   SetIndexLabel(1,"GBP");

   SetIndexStyle(2,DRAW_LINE,STYLE_SOLID );
   SetIndexBuffer( 2, BufferUSD );
   SetIndexLabel(2,"USD");

   SetIndexStyle( 3, DRAW_LINE );
   SetIndexBuffer(3,BufferCAD);
   SetIndexLabel(3,"CAD");

   SetIndexStyle( 4, DRAW_LINE );
   SetIndexBuffer(4,BufferAUD);
   SetIndexLabel(4,"AUD");

   SetIndexStyle( 5, DRAW_LINE );
   SetIndexBuffer( 5,BufferNZD);
   SetIndexLabel(5,"NZD");

   SetIndexStyle(6,DRAW_LINE );
   SetIndexBuffer(6,BufferCHF);
   SetIndexLabel(6,"CHF");

   SetIndexStyle(7,DRAW_LINE );
   SetIndexBuffer(7,BufferJPY);
   SetIndexLabel(7,"JPY"); 
	
   timestart = TimeLocal();
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
	return(0);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start(){	  
   
   int limit;

   int    counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;   
  
//---- TODO: add your code here
   int ilast = -data_hole-1;
   
   if (limit > data_hole && optimize) limit = 2;
   
   for(int i=0;i<limit;i++){               
      if (i>ilast+data_hole)
      {
         ilast = i;
         LoadData(Period(),i);
         BufferEUR[i]=GetStrength_EUR();
         BufferGBP[i]=GetStrength_GBP();
         BufferUSD[i]=GetStrength_USD();
         BufferCAD[i]=GetStrength_CAD();
         BufferAUD[i]=GetStrength_AUD();
         BufferNZD[i]=GetStrength_NZD();
         BufferCHF[i]=GetStrength_CHF();
         BufferJPY[i]=GetStrength_JPY();
      }
            
   }
//----
   return(0);
}

double GetEWO(string symbol, int tf, int offset){
   double TrendCCI[2], EntryCCI[2], Ret;
   TrendCCI[0] = iCustom(symbol,tf,indiName,TrendCCI_Period,EntryCCI_Period,LSMAPeriod,Trend_period,4,offset);
   TrendCCI[1] = iCustom(symbol,tf,indiName,TrendCCI_Period,EntryCCI_Period,LSMAPeriod,Trend_period,4,offset + 1);
   EntryCCI[0] = iCustom(symbol,tf,indiName,TrendCCI_Period,EntryCCI_Period,LSMAPeriod,Trend_period,5,offset);
   EntryCCI[1] = iCustom(symbol,tf,indiName,TrendCCI_Period,EntryCCI_Period,LSMAPeriod,Trend_period,5,offset + 1);
   Ret = TrendCCI[0]/1000 + EntryCCI[0]/1000;
   if (TrendCCI[0] > TrendCCI[1]) Ret = Ret + 0.1;
   else if (TrendCCI[0] < TrendCCI[1]) Ret = Ret - 0.1;
   if (EntryCCI[0] > EntryCCI[1]) Ret = Ret + 0.1;
   else if (EntryCCI[0] < EntryCCI[1]) Ret = Ret - 0.1;
   return (Ret);
}

void LoadData(int tf, int offset)
{
	double v1;

	EURUSD = GetEWO("EURUSD",tf,offset);
	EURGBP = GetEWO("EURGBP",tf,offset);
	EURCAD = GetEWO("EURCAD",tf,offset);
	EURCHF = GetEWO("EURCHF",tf,offset);
	EURJPY = GetEWO("EURJPY",tf,offset);
	EURAUD = GetEWO("EURAUD",tf,offset);
	EURNZD = GetEWO("EURNZD",tf,offset);
	GBPUSD = GetEWO("GBPUSD",tf,offset);
	GBPCAD = GetEWO("GBPCAD",tf,offset);
	GBPCHF = GetEWO("GBPCHF",tf,offset);
	GBPJPY = GetEWO("GBPJPY",tf,offset);
	GBPAUD = GetEWO("GBPAUD",tf,offset);
	GBPNZD = GetEWO("GBPNZD",tf,offset);
	USDCAD = GetEWO("USDCAD",tf,offset);
	USDCHF = GetEWO("USDCHF",tf,offset);
	USDJPY = GetEWO("USDJPY",tf,offset);
	AUDUSD = GetEWO("AUDUSD",tf,offset);
	NZDUSD = GetEWO("NZDUSD",tf,offset);
	CADCHF = GetEWO("CADCHF",tf,offset);
	CADJPY = GetEWO("CADJPY",tf,offset);
	AUDCAD = GetEWO("AUDCAD",tf,offset);
	NZDCAD = GetEWO("NZDCAD",tf,offset);
	AUDCHF = GetEWO("AUDCHF",tf,offset);
	AUDJPY = GetEWO("AUDJPY",tf,offset);
	AUDNZD = GetEWO("AUDNZD",tf,offset);
	NZDCHF = GetEWO("NZDCHF",tf,offset);
	NZDJPY = GetEWO("NZDJPY",tf,offset);
	CHFJPY = GetEWO("CHFJPY",tf,offset);
		
}

double GetStrength_EUR(){
   double result = 0;
   double v1;

   v1 = EURUSD;   if (v1==0) return(0);   if (v1>0) result+=1; else if (v1<0) result-=1;
   v1 = EURGBP;   if (v1==0) return(0);   if (v1>0) result+=1; else if (v1<0) result-=1;
   v1 = EURCAD;   if (v1==0) return(0);   if (v1>0) result+=1; else if (v1<0) result-=1;
   v1 = EURCHF;   if (v1==0) return(0);   if (v1>0) result+=1; else if (v1<0) result-=1;
   v1 = EURAUD;   if (v1==0) return(0);   if (v1>0) result+=1; else if (v1<0) result-=1;
   v1 = EURNZD;   if (v1==0) return(0);   if (v1>0) result+=1; else if (v1<0) result-=1;
   v1 = EURJPY;   if (v1==0) return(0);   if (v1>0) result+=1; else if (v1<0) result-=1;  
   return(result);
}

double GetStrength_GBP(){
   double result = 0;
   double v1;

   v1 = GBPUSD;   if (v1==0) return(0);   if (v1>0) result+=1; else if (v1<0) result-=1;
   v1 = EURGBP;   if (v1==0) return(0);   if (v1<0) result+=1; else if (v1>0) result-=1;
   v1 = GBPCAD;   if (v1==0) return(0);   if (v1>0) result+=1; else if (v1<0) result-=1;
   v1 = GBPCHF;   if (v1==0) return(0);   if (v1>0) result+=1; else if (v1<0) result-=1;
   v1 = GBPAUD;   if (v1==0) return(0);   if (v1>0) result+=1; else if (v1<0) result-=1;
   v1 = GBPNZD;   if (v1==0) return(0);   if (v1>0) result+=1; else if (v1<0) result-=1;
   v1 = GBPJPY;   if (v1==0) return(0);   if (v1>0) result+=1; else if (v1<0) result-=1;
   
   return(result);
}

double GetStrength_USD(){
   double result = 0;
   double v1;

   v1 = EURUSD;   if (v1==0) return(0);   if (v1<0) result+=1; else if (v1>0) result-=1;
   v1 = GBPUSD;   if (v1==0) return(0);   if (v1<0) result+=1; else if (v1>0) result-=1;
   v1 = USDCAD;   if (v1==0) return(0);   if (v1>0) result+=1; else if (v1<0) result-=1;
   v1 = USDCHF;   if (v1==0) return(0);   if (v1>0) result+=1; else if (v1<0) result-=1;
   v1 = AUDUSD;   if (v1==0) return(0);   if (v1<0) result+=1; else if (v1>0) result-=1;
   v1 = NZDUSD;   if (v1==0) return(0);   if (v1<0) result+=1; else if (v1>0) result-=1;
   v1 = USDJPY;   if (v1==0) return(0);   if (v1>0) result+=1; else if (v1<0) result-=1;
   
   return(result);
}

double GetStrength_CAD(){
   double result = 0;
   double v1;

   v1 = EURCAD;   if (v1==0) return(0);   if (v1<0) result+=1; else if (v1>0) result-=1;
   v1 = GBPCAD;   if (v1==0) return(0);   if (v1<0) result+=1; else if (v1>0) result-=1;
   v1 = USDCAD;   if (v1==0) return(0);   if (v1<0) result+=1; else if (v1>0) result-=1;
   v1 = CADCHF;   if (v1==0) return(0);   if (v1>0) result+=1; else if (v1<0) result-=1;
   v1 = AUDCAD;   if (v1==0) return(0);   if (v1<0) result+=1; else if (v1>0) result-=1;
   v1 = NZDCAD;   if (v1==0) return(0);   if (v1<0) result+=1; else if (v1>0) result-=1;
   v1 = CADJPY;   if (v1==0) return(0);   if (v1>0) result+=1; else if (v1<0) result-=1;
   
   return(result);
}

double GetStrength_AUD(){
   double result = 0;
   double v1;

   v1 = AUDUSD;   if (v1==0) return(0);   if (v1>0) result+=1; else if (v1<0) result-=1;
   v1 = GBPAUD;   if (v1==0) return(0);   if (v1<0) result+=1; else if (v1>0) result-=1;
   v1 = AUDCAD;   if (v1==0) return(0);   if (v1>0) result+=1; else if (v1<0) result-=1;
   v1 = AUDCHF;   if (v1==0) return(0);   if (v1>0) result+=1; else if (v1<0) result-=1;
   v1 = EURAUD;   if (v1==0) return(0);   if (v1<0) result+=1; else if (v1>0) result-=1;
   v1 = AUDNZD;   if (v1==0) return(0);   if (v1>0) result+=1; else if (v1<0) result-=1;
   v1 = AUDJPY;   if (v1==0) return(0);   if (v1>0) result+=1; else if (v1<0) result-=1;
   
   return(result);
}

double GetStrength_NZD(){
   double result = 0;
   double v1;

   v1 = NZDUSD;   if (v1==0) return(0);   if (v1>0) result+=1; else if (v1<0) result-=1;
   v1 = GBPNZD;   if (v1==0) return(0);   if (v1<0) result+=1; else if (v1>0) result-=1;
   v1 = NZDCAD;   if (v1==0) return(0);   if (v1>0) result+=1; else if (v1<0) result-=1;
   v1 = NZDCHF;   if (v1==0) return(0);   if (v1>0) result+=1; else if (v1<0) result-=1;
   v1 = EURNZD;   if (v1==0) return(0);   if (v1<0) result+=1; else if (v1>0) result-=1;
   v1 = AUDNZD;   if (v1==0) return(0);   if (v1<0) result+=1; else if (v1>0) result-=1;
   v1 = NZDJPY;   if (v1==0) return(0);   if (v1>0) result+=1; else if (v1<0) result-=1;
   
   return(result);
}

double GetStrength_CHF(){
   double result = 0;
   double v1;

   v1 = USDCHF;   if (v1==0) return(0);   if (v1<0) result+=1; else if (v1>0) result-=1;
   v1 = GBPCHF;   if (v1==0) return(0);   if (v1<0) result+=1; else if (v1>0) result-=1;
   v1 = NZDCHF;   if (v1==0) return(0);   if (v1<0) result+=1; else if (v1>0) result-=1;
   v1 = CADCHF;   if (v1==0) return(0);   if (v1<0) result+=1; else if (v1>0) result-=1;
   v1 = EURCHF;   if (v1==0) return(0);   if (v1<0) result+=1; else if (v1>0) result-=1;
   v1 = AUDCHF;   if (v1==0) return(0);   if (v1<0) result+=1; else if (v1>0) result-=1;
   v1 = CHFJPY;   if (v1==0) return(0);   if (v1>0) result+=1; else if (v1<0) result-=1;
   
   return(result);
}

double GetStrength_JPY(){
   double result = 0;
   double v1;

   v1 = USDJPY;   if (v1==0) return(0);   if (v1<0) result+=1; else if (v1>0) result-=1;
   v1 = GBPJPY;   if (v1==0) return(0);   if (v1<0) result+=1; else if (v1>0) result-=1;
   v1 = NZDJPY;   if (v1==0) return(0);   if (v1<0) result+=1; else if (v1>0) result-=1;
   v1 = CADJPY;   if (v1==0) return(0);   if (v1<0) result+=1; else if (v1>0) result-=1;
   v1 = EURJPY;   if (v1==0) return(0);   if (v1<0) result+=1; else if (v1>0) result-=1;
   v1 = AUDJPY;   if (v1==0) return(0);   if (v1<0) result+=1; else if (v1>0) result-=1;
   v1 = CHFJPY;   if (v1==0) return(0);   if (v1<0) result+=1; else if (v1>0) result-=1;
   
   return(result);
}

